package com.example.myfirstapplication

import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.CompoundButton
import com.example.myfirstapplication.utils.BaseActivity
import com.example.myfirstapplication.utils.Tag
import com.example.myfirstapplication.utils.myToast
import kotlinx.android.synthetic.main.activity_second.*

class SecondActivity : BaseActivity(),CompoundButton.OnCheckedChangeListener {
   /* private lateinit var btnSecond: Button
    private lateinit var editTxtSecond: EditText*/
    private var interrst= mutableListOf<String>()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_second)
        val revBundle = intent.extras
        Log.i(Tag, "SecondActivity revData:" + revBundle.toString())
        val revData1 = revBundle?.getString("myData")
        val revData2 = revBundle?.getString("myDataKey")
        Log.i(Tag, "SecondActivity revData1:" + revData1.toString())
        Log.i(Tag, "SecondActivity revData2:" + revData2.toString())
        myToast(this, "这是第二个界面")
        Log.i(Tag, "SecondActivity: " + this.toString())
       /* editTxtSecond = findViewById(R.id.editTxt_secondAct)
        btnSecond = findViewById(R.id.btn_secondAct)*/
        btn_secondAct.setOnClickListener {
            val inputData = editTxt_secondAct.text.toString()
            val intentObj = Intent(this, MainActivity::class.java)
            val reCallData=Bundle()
            reCallData.putString("inputData",inputData)
            intentObj.putExtras(reCallData)
     //       startActivity(intentObj)
            setResult(Activity.RESULT_OK,intentObj)
            finish() //销毁当前activity
        }
        btn_end.setOnClickListener{
            Log.i(Tag,"选中的值：$interrst")
            var interestVal=interrst.toString()
            interestVal=interestVal.substring(1,interestVal.length-1)
            editTxt_secondAct.setText(interestVal)
        }
        chb_music.setOnCheckedChangeListener(this)
        chb_read.setOnCheckedChangeListener(this)
        chb_film.setOnCheckedChangeListener(this)
        chb_trip.setOnCheckedChangeListener(this)
        chb_game.setOnCheckedChangeListener(this)
        btn_radioGroup.setOnClickListener{
         //   goActivity(this,RadioGroup::class.java)
            val intentObj=Intent(this,RadioGroup::class.java)
            startActivityForResult(intentObj,2)
        }
    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        val revData=data?.extras
        when(requestCode){
            2->{
                when(resultCode){
                    Activity.RESULT_OK->{
                        val radioVal=revData?.getString("radioVal")
                        editTxt_secondAct.setText(radioVal)
                    }
                }
            }
        }
    }
    override fun onCheckedChanged(buttoView:CompoundButton?,isChecked: Boolean){
        Log.i(Tag,"in onChenkedChanged")
        val value=buttoView?.text.toString()
        if(isChecked){
            interrst.add(value)
            Log.i(Tag,"选中：$interrst")
        }
        else{
            interrst.remove(value)
            Log.i(Tag,"取消：$interrst")
        }
    }
}
